package flca.voicenav.util;

import org.garret.perst.Rectangle;

public class RectangleHelper
{
	private RectangleHelper() {}
	
	public static Rectangle updateRectangle(int lat, int lon, Rectangle aRect)
	{
		double bottom, left, top, right;
		
		if (aRect != null) {
			bottom = aRect.getTop();  //this is because the Perst doc is not good!
			left = aRect.getLeft();
			top = aRect.getBottom(); //this is because the Perst doc is not good!
			right = aRect.getRight();
		} else {
			bottom = top = lat;
			left = right = lon;
		}
		
		if (lat < bottom) 	{bottom = lat;};
		if (lat > top) 		{top = lat;};
		if (lon < left) 	{left = lon;};
		if (lon > right)	{right = lon;};
		
		Rectangle result = new Rectangle((int) bottom, (int) left, (int) top, (int) right);
		return result;
	}
}
